{extend name="admin/base" /}
{block name="resources"}
<style>
.img-box{width:60px;height:60px;border:1px dashed #4685fd;position: relative;display: flex;    overflow: hidden;}
.img-info{
	width: 100%;
	height: 100%;
	margin: 0 auto;
	line-height: 100%;
	vertical-align: middle;
}
.default-img-logo{display:inline-block;width:25px}
dl.input-item-inline {
	width: 32%;
	clear: unset;
	display: inline-block;
	box-sizing: border-box;
}
dl.input-item-inline dd{
	width: 48%;
}
.item-line {
	width: 36%!important;
}
.hint {
	color: rgba(0,0,0,.3);
	margin-top: 20px;
}
</style>

{/block}
{block name="main"}
<div class="set-style">
	{volist name="$right_config" id="config" }
	<div class="set-div" data-key="{$key}" data-title-edit-enable="$config.title_edit_enable">
		<h4><span></span>{$config.edit_title}</h4>
		<dl {if condition="$config.title_edit_enable eq 0" }style="display:none;"{/if}>
			<dt>名称：</dt>
			<dd>
				<input type="text" class="input-common" id="{$key}_title" value="{$config.title}"/>
			</dd>
		</dl>
		<dl>
			<dt>条件：</dt>
			<dd>
				<textarea class="textarea-common" id="{$key}_condition">{$config.condition}</textarea>
			</dd>
		</dl>
		<dl>
			<dt>权益：</dt>
			<dd>
				<textarea class="textarea-common" id="{$key}_right">{$config.right}</textarea>
			</dd>
		</dl>
		<dl>
			<dt>奖励：</dt>
			<dd>
				<textarea class="textarea-common" id="{$key}_reward">{$config.reward}</textarea>
			</dd>
		</dl>
	</div>
	{/volist}
	
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="setConfigAjax();">保存</button></dd>
	</dl>
</div>

<script>

function setConfigAjax() {

    var check_res = true;
    var data = {};
    $(".set-div").each(function(){
        var id = $(this).attr('data-key');
        var title = $(this).find("#"+ id +"_title").val();
        var condition = $(this).find("#"+ id +"_condition").val();
        var right = $(this).find("#"+ id +"_right").val();
        var reward = $(this).find("#"+ id +"_reward").val();
        data[id] = {
            title : title,
            condition : condition,
            right : right,
            reward : reward,
		};
        if(title === ''){
            $(this).find("#"+ id +"_title").focus();
            showTip('请输入名称');
            check_res = false;
            return false;
        }
        if(condition === ''){
            $(this).find("#"+ id +"_condition").focus();
            showTip('请输入条件说明');
            check_res = false;
            return false;
		}
        if(right === ''){
            $(this).find("#"+ id +"_right").focus();
            showTip('请输入权益说明');
            check_res = false;
            return false;
        }
        if(right === ''){
            $(this).find("#"+ id +"_right").focus();
            showTip('请输入奖励说明');
            check_res = false;
            return false;
        }
	})
	if(check_res === false) return false;


	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/rightSet')}",
		data : {
			json : JSON.stringify(data)
		},
		success : function(data) {
			if (data["code"] > 0) {
				showTip(data["message"],"success");
				setTimeout(function(){window.location.reload();},2000);
			} else {
				showTip(res.message,"error");
			}
		}
	});
}
</script>
{/block}